/**
 * 
 */
package com.study.handler.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.study.handler.GateWayHandler;
import com.study.handler.entity.GatewayHandlerEntity;
import com.study.handler.mapper.GatewayHandlerMapper;
import com.study.handler.util.SpringUtils;

/**
 * @author Administrator
 * @date 2019年5月10日
 */
@Component
public class GateWayHandlerService {

	 @Autowired
	 private GatewayHandlerMapper gatewayHandlerMapper;
	 
	 public GateWayHandler getHandlers(){
		 GatewayHandlerEntity firstGateWay = gatewayHandlerMapper.getFirstGateWay();
		 if(firstGateWay == null){
			 return null;
		 }
		 GateWayHandler gateWayHandler = (GateWayHandler) SpringUtils.getBean(firstGateWay.getHandlerId());
		 GateWayHandler first = gateWayHandler;
		 
		 GatewayHandlerEntity gateWay = firstGateWay;
		 while(gateWay.getNextHandlerId() !=null){
			 String handlerId = gateWay.getNextHandlerId();
			 gateWay = gatewayHandlerMapper.getByHandler(handlerId);
			 
			 GateWayHandler next = (GateWayHandler) SpringUtils.getBean(handlerId);
			 gateWayHandler.setNextGateWayHandler(next);
			 gateWayHandler = next;
			 
		 }
		 return first;
	 }

}
